function reverseList(head) {
    if (!head || !head.next) return list;
    let pre = null; // 相当于next.next
    while (head) {
        next = head.next;
        head.next = pre;
        pre = head
        head = next
    }
    return pre

}

// 暂存两个变量 pre与head,next 每次循环最先暂存next pre变成当前 head 变为当前的下一个 每次只变 head.next


// 链表的基本机构
function ListNode(val) {
    this.name = val;
    this.next = null;  // 一般是下一个的指针 最后一个为null
}

var a = new ListNode(1);
var b = new ListNode(2);
var c = new ListNode(3);
a.next = b;
b.next = c;

let head = a;
while (head) {
    console.log("转换前", head.name);
    head = head.next
}

head = reverseList(a);

while (head) {
    console.log("转换后", head.name);
    head = head.next
}